<template>
  <div class="signInDialog">
    <el-input
      v-model="idcard"
      ref="hformeridcard"
      placeholder="请输入"
      style="width: 300px"
      :disabled="inputDisabled"
    >
      <template v-if="!disabled">
        <el-button
          slot="append"
          type="danger"
          @click="handleRequest"
          v-if="isShowLoading"
          >验资</el-button
        >
        <el-button
          slot="append"
          v-else
          v-loading="isShowLoading"
          style="background: #ccc"
          >验资中</el-button
        >
      </template>
    </el-input>
    <el-alert
      :title="'验资结果：' + yanziResult"
      :type="type"
      v-if="yanziResult"
    >
    </el-alert>
  </div>
</template>
<script>
import { handleYanzi } from "@/api/hgyw/signin";
export default {
  props: {
    idCard: {
      type: String,
      default: "",
    },
    eid: {
      type: String,
      default: "0000",
    },
    yzMsg: {
      type: String,
      default: "",
    },
    disabled: { type: Boolean, default: null },
    inputDisabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      idcard: "",
      yanziResult: "",
      type: "success",
      isShowLoading: true,
      // disabled: false,
    };
  },
  watch: {
    idcard: {
      handler: function (val) {
        this.$emit("changeIDCard", val);
      },
      immediate: true,
    },
    idCard: {
      handler: function (val) {
        this.idcard = val;
      },
      immediate: true,
    },
    yzMsg: {
      handler: function (val) {
        this.yanziResult = val;
      },
      immediate: true,
    },
  },
  mounted() {
    if (this.idCard) {
      this.idcard = this.idCard;
    }
    this.yanziResult = this.yzMsg;
  },
  methods: {
    handleRequest() {
      this.isShowLoading = false;
      let data = { idCard: this.idcard, eid: this.eid };
      if (!this.eid) {
        data.eid = "0000";
      }
      handleYanzi(data)
        .then((res) => {
          if (res.success) {
            let result = {
              res:
                "恭喜您，验资成功！" +
                res.data.buy.msg +
                "|" +
                res.data.register.msg +
                "|" +
                res.data.sell.msg,
              yzno: res.data.yzno,
              idCard: this.idcard,
            };

            this.type = "success";
            this.yanziResult = result.res;
            this.msgSuccess("恭喜您，验资成功！");
            this.$emit("yanziSuccess", result);
            this.isShowLoading = true;
          } else {
            this.isShowLoading = true;
            if (res.code == 40600) {
              this.msgFormsWarning(res.data);
            } else {
              this.type = "error";
              this.yanziResult = res.msg;
              this.msgError(res.msg);
            }
          }
        })
        .catch(() => {
          this.isShowLoading = true;
        });
    },
  },
};
</script>
<style lang="stylus">
.signInDialog {
  display: flex;
  justify-content: flex-start;
  flex-direction: column;

  .el-dialog__header {
    background: #f1f1f1;
  }

  .el-input-group__append button.el-button {
    background-color: #F56C6C;
    color: #fff;
  }
}
</style>